package draw;

import pulpcore.sprite.Sprite;
import pulpcore.image.CoreGraphics;
import pulpcore.image.Colors;
import pulpcore.Stage;
import pulpfizz.pulp.body.BodySprite;
import pulpfizz.pulp.body.PhysicsLayer;
import org.jbox2d.dynamics.joints.Joint;
import org.jbox2d.dynamics.Body;
import goliath.BasicDemo;

/**
 * Draws a line depicting two bodies connected by a joint.
 * @author will
 * @date Aug 9, 2008 2:05:14 AM
 */
public class JointSprite extends Sprite {
    PhysicsLayer p = BasicDemo.getPhysics();

    Body body1;
    Body body2;

    public JointSprite(BodySprite body1, BodySprite body2) {
        super(0,0, Stage.getWidth(),Stage.getHeight());
        this.body1=body1.getBody();
        this.body2=body2.getBody();
    }

    public JointSprite(Joint j) {
        super(0,0, Stage.getWidth(),Stage.getHeight());
        body1=j.getBody1();
        body2=j.getBody2();
    }

    public void update(int elapsedTime) {
        super.update(elapsedTime);
        this.setDirty(true);
    }

    protected void drawSprite(CoreGraphics g) {
        g.setColor(Colors.GREEN);
        g.drawLine(p.getCanvasX(body1),p.getCanvasY(body1),p.getCanvasX(body2),p.getCanvasY(body2));
    }
}
